import React, { useEffect, useRef } from 'react'

const useDebpunce = ((cllback, delay) => {
    const timer = useRef(null)

    useEffect(() => {
        return () => {
            if (timer.current) {
                clearTimeout(timer.current)
            }
        }
    })
    return (...dle) => {
        if (timer.current) {
            clearTimeout(timer.current)
        }
         timer.current=setTimeout(() => {
                cllback(...dle)
            },delay);
    }
})

export default useDebpunce
